package com.ruoyi.caigou.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.caigou.domain.BuyComparePriceGoods;
import com.ruoyi.caigou.service.IBuyComparePriceGoodsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购比价的商品详情Controller
 *
 * @author lvql
 * @date 2024-11-02
 */
@RestController
@RequestMapping("/comparePriceGoods")
public class BuyComparePriceGoodsController extends BaseController {
    @Autowired
    private IBuyComparePriceGoodsService buyComparePriceGoodsService;

    /**
     * 查询采购比价的商品详情列表
     */
    @RequiresPermissions("caigou:comparePriceGoods:list")
    @GetMapping("/list")
    public TableDataInfo list(BuyComparePriceGoods buyComparePriceGoods) {
        startPage();
        List<BuyComparePriceGoods> list = buyComparePriceGoodsService.selectBuyComparePriceGoodsList(buyComparePriceGoods);
        return getDataTable(list);
    }

    /**
     * 查询采购比价的商品详情列表
     */
    @RequiresPermissions("caigou:comparePriceGoods:list")
    @PostMapping("/listByComparePriceCode")
    public AjaxResult listByComparePriceCode(@RequestBody List<String> codeList) {

        logger.info("BuyComparePriceGoodsController listByComparePriceCode params {}", codeList);
        if (codeList.isEmpty()) {
            return AjaxResult.error("缺少参数");
        }


        List<BuyComparePriceGoods> list = buyComparePriceGoodsService.selectBuyComparePriceGoodsListByComparePriceCode(codeList);
        return AjaxResult.success(list);
    }

    /**
     * 导出采购比价的商品详情列表
     */
    @RequiresPermissions("caigou:comparePriceGoods:export")
    @Log(title = "采购比价的商品详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyComparePriceGoods buyComparePriceGoods) {
        List<BuyComparePriceGoods> list = buyComparePriceGoodsService.selectBuyComparePriceGoodsList(buyComparePriceGoods);
        ExcelUtil<BuyComparePriceGoods> util = new ExcelUtil<BuyComparePriceGoods>(BuyComparePriceGoods.class);
        util.exportExcel(response, list, "采购比价的商品详情数据");
    }

    /**
     * 获取采购比价的商品详情详细信息
     */
    @RequiresPermissions("caigou:comparePriceGoods:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(buyComparePriceGoodsService.selectBuyComparePriceGoodsById(id));
    }

    /**
     * 新增采购比价的商品详情
     */
    @RequiresPermissions("caigou:comparePriceGoods:add")
    @Log(title = "采购比价的商品详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyComparePriceGoods buyComparePriceGoods) {
        return toAjax(buyComparePriceGoodsService.insertBuyComparePriceGoods(buyComparePriceGoods));
    }

    /**
     * 修改采购比价的商品详情
     */
    @RequiresPermissions("caigou:comparePriceGoods:edit")
    @Log(title = "采购比价的商品详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyComparePriceGoods buyComparePriceGoods) {
        return toAjax(buyComparePriceGoodsService.updateBuyComparePriceGoods(buyComparePriceGoods));
    }

    /**
     * 删除采购比价的商品详情
     */
    @RequiresPermissions("caigou:comparePriceGoods:remove")
    @Log(title = "采购比价的商品详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(buyComparePriceGoodsService.deleteBuyComparePriceGoodsByIds(ids));
    }
}
